﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DRHotel_v1.Classes.DBManagers;

namespace DRHotel_v1.RoomAvaAndBooking
{
    public partial class RoomAvaSearchFrm : Form
    {
        ArrayList avaRooms;
        public RoomAvaSearchFrm()
        {
            InitializeComponent();
        }

        private void btnSearchRoomAva_Click(object sender, EventArgs e)
        {
            DateTime desInDT = dtpDesIn.Value;
            DateTime desOutDT = dtpDesOut.Value;
            string roomType = cbbRoomType.Text;
            string bedType = cbbBedType.Text;
            bool smoking = cbxSmoking.Checked;
            avaRooms = RoomAvaAndBookingDBManager.SearchRoomAva(roomType,bedType,smoking,desInDT,desOutDT);
            if (avaRooms.Count != 0)
            {
                lblNoResult.Text = "Rooms founded: " + avaRooms.Count.ToString();
                lblNoResult.ForeColor = Color.Green;
                dgvSearchResult.DataSource = avaRooms;
                dgvSearchResult.Columns[0].HeaderText = "Room ID";
                //dgvSearchResult.Columns[0].Frozen = true;
                dgvSearchResult.Columns[1].HeaderText = "Room Type";
                dgvSearchResult.Columns[2].HeaderText = "Bed Type";
                dgvSearchResult.Columns[3].HeaderText = "Capacity";
                dgvSearchResult.Columns[4].HeaderText = "Room Rates";
                dgvSearchResult.Columns[5].Visible = false;
                dgvSearchResult.Columns[6].HeaderText = "Room Status";
                dgvSearchResult.Columns[7].HeaderText = "Remark";
            }
            else
            {
                lblNoResult.Text = "No Room founded!";
                lblNoResult.ForeColor = Color.Red;
            }
            
        }

        private void RoomAvaSearchFrm_Load(object sender, EventArgs e)
        {
            cbbRoomType.DataSource = RoomAvaAndBookingDBManager.GetRoomType();
            cbbBedType.DataSource = RoomAvaAndBookingDBManager.GetBedType();
        }

        private void dgvSearchResult_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewTextBoxCell cellResNo = (DataGridViewTextBoxCell)
                dgvSearchResult.Rows[e.RowIndex].Cells[0];

            int selectedResNo = Convert.ToInt32(cellResNo.Value);
            tbxRoomID.Text = selectedResNo.ToString();

        }

        private void btnBook_Click(object sender, EventArgs e)
        {
            if (tbxRoomID.TextLength == 0)
            {
                MessageBox.Show("Please select a record to continue!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            RoomBookingFrm frm = new RoomBookingFrm();
            frm.rm = RoomAvaAndBookingDBManager.GetRoomByID(tbxRoomID.Text);
            frm.checkInDT = dtpDesIn.Value;
            frm.checkOutDT = dtpDesOut.Value;
            frm.ShowDialog();
        }

        private void cbbRoomType_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbbBedType.DataSource = RoomAvaAndBookingDBManager.GetBedTypeByRoomType(cbbRoomType.Text);
        }

        private void cbbBedType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //cbbRoomType.DataSource = RoomAvaAndBookingDBManager.GetRoomTypeByBedType(cbbBedType.Text);
        }
    }
}
